import java.util.Arrays;

public class test {
    public static void main(String[] args) {
        int[][] array={{1,2,3},{4,5,6}};
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println("==========");
        for (int[] tmpArray:array) {
            for (int x:tmpArray){
                System.out.print(x+" ");
            }
            System.out.println();
        }
        System.out.println("==========");
        String ret=Arrays.deepToString(array);
        System.out.println(ret);
    }

    public static void main07(String[] args) {
        int[] ret=new int[10];
        //Arrays.fill(ret,-1);
        Arrays.fill(ret,1,3,-1);
        System.out.println(Arrays.toString(ret));
    }
    public static void main06(String[] args) {
        int[] array={1,2,3,4,5};
        //int[] copy=Arrays.copyOf(array,array.length*2); //扩容两倍
        int[] copy=Arrays.copyOfRange(array,1,3);
        System.out.println(Arrays.toString(copy));
    }
    //冒泡排序
    public static void bubbleSort(int[] array){
        for (int i = 0; i <array.length-1 ; i++) {
            boolean flg=false;
            for (int j = 0; j <array.length-1-i ; j++) {
                if (array[j]>array[j+1]){
                    int tep=0;
                    tep=array[j];
                    array[j]=array[j+1];
                    array[j+1]=tep;
                    flg=true;
                }
            }
            if (flg==false){
                return;
            }
        }
    }
    //二分查找
    public static int binaruSearch(int[] array,int key){
        int left=0;
        int right=array.length-1;
        while (left>=right){
            int mid=(right+left)/2;
            if (array[mid]==key){
                return mid;
            } else if (array[mid]>key) {
                right=mid-1;
            }else {
                left=mid+1;
            }
        }
        return -1;
    }

    public static void main05(String[] args) {
        int[] array={1,43,2,5,7,32,46};
        System.out.println(Arrays.toString(array));
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));//从小到大的排序
        int index=Arrays.binarySearch(array,32);
        System.out.println(index);
    }

    public static void main04(String[] args) {
        int[] array={1,2,3,4,5};
        int index=binaruSearch(array,9);
        System.out.println(index);
    }
    public static String myToString(int[] array){
        String ret="[";
        for (int i = 0; i <array.length ; i++) {
            ret+=array[i];
            if (i!=array.length-1){
                ret+=", ";
            }
        }
        ret+="]";
        return ret;
    }

    public static void main03(String[] args) {
        int[] array={1,2,3,4,5};
        System.out.println(myToString(array));
    }

    //把数组中的每个数据扩大到两倍
    public static int[] func1(int[] array){
        int[] ret=new int[array.length];
        for (int i = 0; i <array.length ; i++) {
            ret[i]=array[i]*2;
        }
        return ret;
    }
    public static void func2(int[] array){
        for (int i = 0; i <array.length ; i++) {
            array[i]=array[i]*2;
        }
    }

    public static void main02(String[] args) {
        int[] array={1,2,3,4,5};
        func2(array);
        System.out.println(Arrays.toString(array));
    }

    public static void main01(String[] args) {
        int[] array={1,2,3,4,5};
        int[] temp=func1(array);
        System.out.println(Arrays.toString(array));
        System.out.println(Arrays.toString(temp));
    }
}
